//
//  hotCityViewController.m
//  INAlienLand
//
//  Created by dllo on 15/6/30.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "hotCityViewController.h"
#import "destinationInterfaceViewController.h"
#import "HTTPTool.h"
#import "DestCollectionViewCell.h"
#import "destCollectionHeaderReusableView.h"
#import "arerModel.h"
#import "UIImageView+WebCache.h"
#import "dataInArr.h"
#import "placeDetail.h"
#import "placeDetailTableViewCell.h"
#import "MapViewController.h"
#import "imageViewController.h"
#import "AllImage.h"
#import "tipsViewController.h"

#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height

@interface hotCityViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,retain)UITableView *hottableView;
@property (nonatomic,copy)NSString *str;
@property (nonatomic,retain)AllImage *headerImage;
@property (nonatomic,retain)UILabel *lableName;
@property (nonatomic,retain)UILabel *lableRate;
@property (nonatomic,retain)UILabel *lableItro;
@property (nonatomic,retain)NSMutableArray *placeDetailArr;
@property (nonatomic,retain)UIImageView *imageView;
@property (nonatomic,assign)BOOL isLike;

@end

@implementation hotCityViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBarHidden =YES;
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
   // [[UIApplication sharedApplication] setStatusBarHidden:YES];
    //          喜欢按钮
    UIBarButtonItem *likeButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"我的"] style:UIBarButtonItemStylePlain target:self action:@selector(like:)];
    //   分享按钮
    UIBarButtonItem *shareButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"位置"] style:UIBarButtonItemStylePlain target:self action:@selector(share:)];
    NSArray *buttonArr = [NSArray arrayWithObjects:likeButton,shareButton,nil];
    self.navigationItem.rightBarButtonItems = buttonArr;
    [shareButton release];
    [likeButton release];
    self.navigationController.navigationBar.clipsToBounds = YES;
   //self.navigationController.navigationBar. alpha  = 0.001;
    //[self.navigationController setNavigationBarHidden:YES animated:YES];
    [self createData];
    [self createtable];
}
//喜欢按钮方法
- (void)like:(UIButton *)button{
    if (self.isLike == NO) {
        self.isLike = YES;
        [self.navigationItem.rightBarButtonItem setImage:[UIImage imageNamed:@"推荐"]];
    }else if(self.isLike == YES){
        [self.navigationItem.rightBarButtonItem setImage:[UIImage imageNamed:@"我的"]];
        self.isLike = NO;
    }
}
//分享按钮方法
- (void)share:(UIButton *)button{
    MapViewController *map = [[MapViewController alloc]init];
    map.x =self.arer.x ;
      map.y =self.arer.y;
    NSLog(@"%@",self.arer.x);
    [self.navigationController pushViewController:map animated:YES];
    
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://123456789"]];
}
-(void)createtable
{
    
    self.hottableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0,WIDTH , HEIGHT-64-49) style:UITableViewStylePlain];
    [self.view addSubview:self.hottableView];
    
    self.hottableView.delegate = self;
    self.hottableView.dataSource = self;
    UIView *headerview = [[UIView    alloc]initWithFrame:CGRectMake(0, 0, WIDTH, 400)];
    
    UIButton *buttom = [UIButton buttonWithType:UIButtonTypeSystem];
    [buttom setTitle:@"更多分享" forState:UIControlStateNormal];
    [headerview addSubview:buttom];
    buttom.backgroundColor = [UIColor colorWithRed:125/255.00 green:131/255.00 blue:132/255.00 alpha:1.000];
    
    buttom.frame = CGRectMake(100, 300, WIDTH/5, 40);
    [buttom addTarget:self action:@selector(look:) forControlEvents:UIControlEventTouchUpInside];
    buttom.layer.borderWidth = 1;
    buttom.layer.cornerRadius = 20;
    buttom.layer.masksToBounds =YES;
    buttom.titleLabel.font = [UIFont systemFontOfSize:15];
    
    self.hottableView.tableHeaderView = headerview;
    self.headerImage = [[AllImage alloc]initWithFrame:CGRectMake(0, 0, headerview.frame.size.width, HEIGHT/2)];
    [headerview  addSubview:self.headerImage];
    //imageview添加点击手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
    [self.headerImage addGestureRecognizer:tap];
    self.headerImage.userInteractionEnabled = YES;
//    headerImage.layer.borderWidth = 1;
    
    self.lableName = [[UILabel alloc]initWithFrame:CGRectMake(0, headerview.frame.size.height/2  , headerview.frame.size.width, headerview.frame.size.height/8)];
    [headerview addSubview:self.lableName];
    
    self.lableName.textAlignment = NSTextAlignmentCenter;
    self.lableName.font = [UIFont fontWithName:@"Arial" size:30];//设置文字类型与大小
    
//    self.lableRate = [[UILabel alloc]initWithFrame:CGRectMake(0, HEIGHT/3+35, WIDTH, 20)];
//    [headerview addSubview:self.lableRate];
//    self.lableRate.layer.borderWidth = 1;
//    
//    self.lableItro = [[UILabel alloc]initWithFrame:CGRectMake(0, HEIGHT/3+55, WIDTH, 30)];
//    [headerview addSubview:self.lableItro];
//    self.lableItro.textAlignment = NSTextAlignmentCenter;
//    self.lableItro.font=[UIFont systemFontOfSize:15];

    
    
   
    
    
    
    


    
    
}
//手势点击方法
-(void)tapAction:(UIGestureRecognizer *)tap
{
    imageViewController *imageview =[[imageViewController alloc]init];
    [self.navigationController pushViewController:imageview animated:YES];
    imageview.arer = self.arer;
//   NSLog(@"%@",imageview.arer.type);
    
    
}
-(void)look:(UIButton *)button
{
    tipsViewController *tip = [[tipsViewController alloc]init];
    [self.navigationController pushViewController:tip animated:YES];

}
//图片放大
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    
    
    
    scrollView= self.hottableView;
    CGFloat yOffset  = scrollView.contentOffset.y;
    //NSLog(@"%g", scrollView.contentOffset.y);
    if (scrollView.contentOffset.y < 0) {
        self.headerImage.frame = CGRectMake(0, yOffset, self.view.frame.size.width,200 -yOffset);
    }
//    else
//    {
//        self.headerImage.frame = CGRectMake(0, -yOffset, self.view.frame.size.width, 200);
//        
//    }
   
}
//-(void)scrollViewDidScrollToTop:(UIScrollView *)scrollView
//{
//    CGFloat yOffset  = scrollView.contentOffset.y;
//    //NSLog(@"%g", scrollView.contentOffset.y);
//    if (scrollView.contentOffset.y < -200) {
//        self.imageView.frame = CGRectMake(0, yOffset, self.view.frame.size.width, -yOffset);
//    }
//
//}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{

    UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, WIDTH, 50)];
    lable.text =@"beigin";
    return lable;
    
}
//-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
//{
//    return 50;
//}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section ==0) {
        return 3;
    }else{
    return self.placeDetailArr.count;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return 80;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"%f",tableView.contentOffset.y);
    static NSString *reuse  = @"reuse";
    placeDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
    if (!cell) {
        cell = [[placeDetailTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse];
    }
    NSArray *arr = @[@"概况",@"地址",@"到达方式",@"开放时间",@"门票价格",@"联系方式",@"官方网站"];
    cell.titleLable.text= arr[indexPath.row];
    cell.contentLabel.text = self.placeDetailArr[indexPath.row];
    if (indexPath.row !=3 ) {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
        
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}
-(void)createData
{
    [HTTPTool get:[NSString stringWithFormat:@"http://api.breadtrip.com/destination/place/%@/%@/",self.arer.type,self.arer.bId] body:nil HTTPResult:JSON success:^(id result) {
        NSDictionary *Dic = result;
        placeDetail *placedetailDic= [[placeDetail alloc]init];
        [placedetailDic setValuesForKeysWithDictionary:Dic];
        self.placeDetailArr = [NSMutableArray array];
        NSDictionary *inDic = Dic[@"share_args"];
        NSDictionary *qqDic = inDic[@"default"];
        self.str = qqDic[@"shr_image"];
        self.lableName.text = placedetailDic.name;
        self.lableItro.text = placedetailDic.recommended_reason;
        [self.placeDetailArr  addObject:placedetailDic.recommended_reason];
        [self.placeDetailArr  addObject:placedetailDic.address];
        [self.placeDetailArr  addObject:placedetailDic.arrival_type];
        [self.placeDetailArr  addObject:placedetailDic.opening_time];
        [self.placeDetailArr  addObject:placedetailDic.fee];
        [self.placeDetailArr  addObject:placedetailDic.tel];
        [self.placeDetailArr  addObject:placedetailDic.website];
        [self.headerImage    sd_setImageWithURL:[NSURL URLWithString:self.str]];
        [self.hottableView reloadData];
    
    } failure:^(NSError *error) {
        
    }];
    
}
-(void)viewDidDisappear:(BOOL)animated
{
    [self.navigationController setNavigationBarHidden:NO animated:NO];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
